package com.xhl.robot.features.antirecall;

import cc.moecraft.icq.command.CommandArgs;
import cc.moecraft.icq.command.exceptions.CommandNotFoundException;
import cc.moecraft.icq.command.exceptions.NotACommandException;
import cc.moecraft.icq.event.EventHandler;
import cc.moecraft.icq.event.IcqListener;
import cc.moecraft.icq.event.events.message.EventGroupMessage;
import cc.moecraft.icq.sender.returndata.RawReturnData;
import cc.moecraft.icq.sender.returndata.ReturnStatus;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 此类由 Hykilpikonna 在 2018/06/13 创建!
 * Created by Hykilpikonna on 2018/06/13!
 * Github: https://github.com/hykilpikonna
 * QQ: admin@moecraft.cc -OR- 871674895
 *
 * @author Hykilpikonna
 */
public class AntiRecallListener extends IcqListener
{
    //记录群里的信息
    public static HashMap<Long, ArrayList<String>> groupTexts = new HashMap<>();

    @EventHandler
    public void onGroupMessageEvent(EventGroupMessage event)
    {
        try
        {
            // 如果是指令, 就忽略
            CommandArgs.parse(event.getBot().getCommandManager(), event.getMessage(), true);
        }
        catch (NotACommandException | CommandNotFoundException ignored)
        {
            Long groupId = event.getGroupId();
            //判断Map集合对象中是否包含指定的键名，不包括就创建。
            if (!groupTexts.containsKey(groupId)) {
                groupTexts.put(event.getGroupId(), new ArrayList<String>());
            }

            //保存群内的信息到静态变量，格式为 名称+消息
            groupTexts.get(event.getGroupId())
                    .add(event.getBot().getUserManager().getUserFromID(event.getSenderId()).getInfo().getNickname() + " >> " + event.getMessage());
        }
    }
}
